package com.triones.yjj.controller.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.triones.yjj.entity.MemberDO;
import com.triones.yjj.entity.bo.*;
import com.triones.yjj.entity.vo.*;
import com.triones.yjj.service.MemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * 客户管理
 *
 * @Author: triones
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/member")
public class MemberController extends BaseController {

    private final MemberService memberService;

    /**
     * 查询客户列表（分页）
     */
    @GetMapping("/pageList")
    public TableDataInfo<MemberListVO> pageList(MemberListParams params, PageQuery pageQuery) {
        return memberService.pageList(params, pageQuery);
    }

    /**
     * 设置老客或新客
     */
    @Log(title = "客户管理", businessType = BusinessType.UPDATE)
    @PutMapping("/{memberIds}/{type}")
    public R<Void> setMemberToOldOrNew(@PathVariable Long[] memberIds,@NotNull(message = "客户类型不能为空") @PathVariable Integer type) {
        return toAjax(memberService.setMemberToOldOrNew(memberIds,type));
    }

    /**
     * 手动上传老客户手机号
     */
    @PostMapping("/uploadMobile")
    public R<Void> uploadMobiles(@RequestBody OldMemberBO bo) {
        return toAjax(memberService.uploadMobiles(bo));
    }

    /**
     * 查询老客户手机号列表（分页）
     */
    @GetMapping("/oldMemberMobilePageList")
    public TableDataInfo<OldMemberVO> oldMemberMobilePageList(OldMemberParams params, PageQuery pageQuery) {
        return memberService.oldMemberMobilePageList(params, pageQuery);
    }

    /**
     * 删除老客户手机号
     */
    @DeleteMapping("/memberMobile/{ids}")
    public R<Void> delMemberMobiles(@PathVariable Long[] ids) {
        return toAjax(memberService.delMemberMobiles(ids));
    }

    /**
     * 数据统计
     */
    @GetMapping("/memberStats")
    public R<Map> dataShowStats(MemberListParams params) {
        return R.ok(memberService.dataShowStats(params));
    }

    /**
     * 客户信息统计
     */
    @GetMapping("/memberInfoStats/{memberId}")
    public R<Map> memberInfoStats(@PathVariable Long memberId) {
        return R.ok(memberService.memberInfoStats(memberId));
    }

    /**
     * 获取用户详细信息
     */
    @GetMapping(value = "/{memberId}")
    public R<MemberDetailVO> getInfo(@PathVariable Long memberId) {
        return R.ok(memberService.selectDetailById(memberId));
    }

    /**
     * 修改用户
     */
    @Log(title = "客户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody MemberDO dto) {
        return toAjax(memberService.editMember(dto));
    }

    /**
     * 获取客户行为列表（分页）
     */
    @GetMapping("/action/pageList")
    public TableDataInfo<MemberActionListVO> actionPageList(MemberActionParams params, PageQuery pageQuery) {
        return memberService.actionPageList(params, pageQuery);
    }

    /**
     * 获取客户分销列表（分页）
     */
    @GetMapping("/distribution/pageList")
    public TableDataInfo<MemberDistributionListVO> distributionPageList(MemberDistributionParams params, PageQuery pageQuery) {
        return memberService.distributionPageList(params, pageQuery);
    }

    /**
     * 获取客户订单列表（分页）
     */
    @GetMapping("/order/pageList")
    public TableDataInfo<MemberOrderListVO> orderPageList(MemberOrderParams params, PageQuery pageQuery) {
        return memberService.orderPageList(params, pageQuery);
    }

    /**
     * 查询分享的人列表（分页）
     */
    @GetMapping("/share/pageList")
    public TableDataInfo<ShareListVO> sharePageList(ShareListParams params, PageQuery pageQuery) {
        return memberService.sharePageList(params, pageQuery);
    }

    /**
     * 分享的人数据统计
     */
    @GetMapping("/share/stats")
    public R<Map> dataShowSta(ShareListParams params) {
        return R.ok(memberService.shareDataStats(params));
    }

    /**
     * 查询潜在的客户列表（分页）
     */
    @GetMapping("/potential/pageList")
    public TableDataInfo<PotentialListVO> potentialPageList(PotentialListParams params, PageQuery pageQuery) {
        return memberService.potentialPageList(params, pageQuery);
    }

    /**
     * 查询浏览记录列表（分页）
     */
    @GetMapping("/browseRecord/pageList")
    public TableDataInfo<MemberBrowseRecordVO> browseRecordPageList(BrowseRecordListParams params, PageQuery pageQuery) {
        return memberService.browseRecordPageList(params, pageQuery);
    }

    /**
     * 潜在客户数据统计
     */
    @GetMapping("/browse/stats")
    public R<Map> browseStats() {
        return R.ok(memberService.browseStats());
    }

    /**
     * 浏览记录相关统计
     */
    @GetMapping("/browseRecord/stats/{id}")
    public R<Map> browseRecordStats(@PathVariable Long id) {
        return R.ok(memberService.browseRecordStats(id));
    }
}
